package com.github_dididipapa.mall.product.app;

import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import cn.hutool.core.bean.BeanUtil;
import com.github_dididipapa.common.to.SkuInfoTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.github_dididipapa.mall.product.entity.SkuInfoEntity;
import com.github_dididipapa.mall.product.service.SkuInfoService;
import com.github_dididipapa.common.utils.PageUtils;
import com.github_dididipapa.common.utils.R;



/**
 * sku信息
 *
 * @author dididipapa
 * @email not_found@404.com
 * @date 2025-04-26 18:51:11
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    //@RequiresPermissions("product:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:skuinfo:delete")
    public R delete(@RequestBody List<Long> skuIds){
		skuInfoService.removeByIds(skuIds);

        return R.ok();
    }

    /**
     * @description: 远程调用接口查询sku详情
     * @author: dididi_papa
     * @date: 2025/6/25 下午11:11
     * @param: [skuId]
     * @return: com.github_dididipapa.common.to.SkuInfoTo
     **/
    @GetMapping("/skuDetail/{skuId}")
    public SkuInfoTo getSkuInfo(@PathVariable("skuId") Long skuId){
        SkuInfoEntity entity = skuInfoService.getById(skuId);
        SkuInfoTo response = new SkuInfoTo();
        BeanUtil.copyProperties(entity,response);
        return response;
    }
}
